<?php
include "./mysql.class.php";
$filename=array(
 // "faile_detail.txt",
	"save-10000.txt",
	"save-20000.txt",
	'save-30000.txt',
	'save-40000.txt',
	'save-5,60000.txt',
	'save-7,80000.txt',
	'save-9,100000.txt',
	'save-11,12,13,14,150000.txt',
	'save-160000.txt',
	'save-170000.txt',
	'save-175000.txt'
	);
	set_time_limit(0);
	echo "开始时间：".date("H:i:s")."<br>";
	$start_time=time();
	$mysql = new Mysql;
 for($i=0;$i<count($filename);$i++){
// for($i=0;$i<1;$i++){

	echo "$filename[$i]"."内的标准包括:<br>";
	$handle=fopen($filename[$i],"r");
	$j=1;
	$data=array();
	while(!feof($handle)){
		$line=fgets($handle);
		$str=json_decode($line,true);
		//print_r($str);
		$data[$j]=$str;
		$data[$j]=chan($data[$j]);

		if(strlen($data[$j]['data_name'])==0){
			echo "<br>本条数据为空".$j."<br>";
		}else{
			$res=$mysql->Exec($data[$j], "standard");
			if(!$res){
				echo "<br>本条数据插入失败".$j."<br>";
			}
		}
		echo "$j, ";
		$j++;
		// sleep(0.3);
		// if($j>1000){
			// exit();
		// }
	}
	//print_r($data);
	fclose($handle);
	echo "<hr>";
	
}
	echo "结束时间：".date("H:i:s")."<br>";
	$end_time=time();
	echo "开始时间：".date("H:i:s")."<br>";
	echo "结束时间：".date("H:i:s")."<br>";
	$d_time=$end_time-$start_time;
	echo "总计用时：".$d_time."秒"."<br>";
	echo "相当于:".floor($d_time/60)."分钟"."<br>";
	echo "相当于:".round($d_time/3600,2)."小时"."<br>";
	
function chan($arr_old){
	$arr=array();
	$arr['data_name']									=isset($arr_old['资料名称：'])	?$arr_old['资料名称：']:'';
	$arr['data_name']=str_ireplace("'","",$arr['data_name']);
	$arr['stand_type']								=isset($arr_old['标准类别：'])	?$arr_old['标准类别：']:'';
	$arr['stand_lang']								=isset($arr_old['语　　言：'])	?$arr_old['语　　言：']:'';
	$arr['stand_cost']								=isset($arr_old['授权形式：'])	?$arr_old['授权形式：']:'';
	$arr['stand_state']								=isset($arr_old['标准状态：'])	?$arr_old['标准状态：']:'';
	$arr['stand_cancelDate']					=isset($arr_old['作废日期：'])	?$arr_old['作废日期：']:'';
	$arr['stand_cancelDate']=strlen($arr['stand_cancelDate'])<=5?'0000-00-00':$arr['stand_cancelDate'];
	$arr['stand_promulgateDate']			=isset($arr_old['发布日期：'])	?$arr_old['发布日期：']:'';
	$arr['stand_promulgateDate']=strlen($arr['stand_promulgateDate'])<=5?'0000-00-00':$arr['stand_promulgateDate'];
	$arr['stand_executeDate']					=isset($arr_old['实施日期：'])	?$arr_old['实施日期：']:'';
	$arr['stand_executeDate']=strlen($arr['stand_executeDate'])<=5?'0000-00-00':$arr['stand_executeDate'];
	$arr['stand_firstpublicDate']			=isset($arr_old['首发日期：'])	?$arr_old['首发日期：']:'';
	$arr['stand_firstpublicDate']=strlen($arr['stand_firstpublicDate'])<=5?'0000-00-00':$arr['stand_firstpublicDate'];
	$arr['stand_reviewDate']					=isset($arr_old['复审日期：'])	?$arr_old['复审日期：']:'';
	$arr['stand_reviewDate']=strlen($arr['stand_reviewDate'])<=5?'0000-00-00':$arr['stand_reviewDate'];
	$arr['stand_publicDate']					=isset($arr_old['出版日期：'])	?$arr_old['出版日期：']:'';
	$arr['stand_publicDate']=strlen($arr['stand_publicDate'])<=5?'0000-00-00':$arr['stand_publicDate'];
	$arr['stand_id']									=isset($arr_old['标准编号：'])	?$arr_old['标准编号：']:'';
	$arr['stand_title']								=isset($arr_old['标准名称：'])	?$arr_old['标准名称：']:'';
	$arr['stand_title']=str_ireplace("'","",$arr['stand_title']);
	$arr['stand_summary']							=isset($arr_old['标准简介：'])	?$arr_old['标准简介：']:'';
	$arr['stand_summary']=str_ireplace("标准下载解压密码：www.bzxz.net","",$arr['stand_summary']);
	$arr['stand_summary']=str_ireplace("'","",$arr['stand_summary']);
	$arr['stand_replacement']					=isset($arr_old['替代情况：'])	?$arr_old['替代情况：']:'';
	$arr['stand_adopt']								=isset($arr_old['采标情况：'])	?$arr_old['采标情况：']:'';
	$arr['stand_promulgateDepartment']=isset($arr_old['发布部门：'])	?$arr_old['发布部门：']:'';
	$arr['stand_suggestUnit']					=isset($arr_old['提出单位：'])	?$arr_old['提出单位：']:'';
	$arr['stand_relevantDepartment']	=isset($arr_old['归口单位：'])	?$arr_old['归口单位：']:'';
	$arr['stand_competentDepartment']	=isset($arr_old['主管部门：'])	?$arr_old['主管部门：']:'';
	$arr['stand_draftUnit']						=isset($arr_old['起草单位：'])	?$arr_old['起草单位：']:'';
	$arr['stand_draftMan']						=isset($arr_old['起 草 人：'])	?$arr_old['起 草 人：']:'';
	$arr['stand_press']								=isset($arr_old['出 版 社：'])	?$arr_old['出 版 社：']:'';
	$arr['stand_pageNum']							=isset($arr_old['页　　数：'])	?$arr_old['页　　数：']:'';
	$arr['stand_pageNum']=str_ireplace("， ","；",$arr['stand_pageNum']);
	$arr['stand_ISBN']								=isset($arr_old['书　　号：'])	?$arr_old['书　　号：']:'';
	$arr['stand_planNum']							=isset($arr_old['计划单号：'])	?$arr_old['计划单号：']:'';
	$arr['stand_downloadDates']				=isset($arr_old['下载次数：'])	?$arr_old['下载次数：']:'';
	$arr['stand_downloadDates']=str_ireplace("次","",$arr['stand_downloadDates']);
	$arr['stand_downloadDates']=strlen($arr['stand_downloadDates'])==0?'0':$arr['stand_downloadDates'];

	foreach($arr as $k=>$v){
		// $arr[$k]=;
		$arr[$k]=str_ireplace("（参考）","",str_ireplace("◎","",$v));
		//echo $v;
	}
	return $arr;
}

?>
